﻿using SIS.Models.Users.Entities;
using SIS.Repositories.Common;
using SIS.Repositories.Users;
using SIS.Services.Common;
using System;

namespace SIS.Services.Users
{
    public class UserServices : BaseServices<UserInfoEntity>, IUserServices
    {
        private readonly IUserRepository _userRepository;
        public UserServices(IUserRepository userRepository, IBaseRepository<UserInfoEntity> baseRepository) : base(baseRepository)
        {
            _userRepository = userRepository;
        }

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="name">用户名</param>
        /// <param name="passWord">密码</param>
        /// <returns>0：登录成功，-1：用户名不存在，或者密码错误，1：用户被禁用</returns>
        public int LogIn(string name, string passWord)
        {
            var ret = -1;
            var user = _userRepository.GetUserInfoByName(name);
            if (user != null)
            {
                if(user.PassWord==passWord)
                {
                    if (user.Status)
                        ret = 0;
                    else
                        ret = 1;       
                }
            }
            return ret;
        }
    }

}
